package com.jiayi.web.controller.cms;

import com.jiayi.api.JiayiProductService;
import com.jiayi.common.annotation.Log;
import com.jiayi.common.core.domain.AjaxResult;
import com.jiayi.common.core.page.TableDataInfo;
import com.jiayi.common.developutil.ConvertUtils;
import com.jiayi.common.enums.BusinessType;
import com.jiayi.data.converter.JiayiProductConverter;
import com.jiayi.data.entity.request.JiayiProductRequest;
import com.jiayi.data.entity.request.JiayiProductSearchPageRequest;
import com.jiayi.data.entity.request.JiayiProductSearchRequest;
import com.jiayi.data.entity.schema.JiayiProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品展示Controller
 *
 * @author zzx
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/cms/jiayi_product")
public class JiayiProductController {
    @Autowired
    private JiayiProductService jiayiProductService;

    @Autowired
    private JiayiProductConverter jiayiProductconverter;

    /**
     * 查询产品展示列表 分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:list')")
    @PostMapping("/listPage")
    public TableDataInfo listPage(@RequestBody JiayiProductSearchPageRequest request) {
        return jiayiProductService.selectJiayiProductList(request);
    }


    /**
     * 查询产品展示列表 不分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody JiayiProductSearchRequest request) {
        List<JiayiProduct> list = jiayiProductService.selectJiayiProductList(request);
        return AjaxResult.success(ConvertUtils.convert(list, jiayiProductconverter::convertToJiayiProductDTO));
    }

    /**
     * 导出产品展示列表
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:export')")
    @Log(title = "产品展示" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody JiayiProductSearchRequest request, HttpServletResponse response) {
        jiayiProductService.export(request, response);
    }

    /**
     * 获取产品展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(jiayiProductService.selectJiayiProductById(id));
    }

    /**
     * 新增产品展示
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:add')")
    @Log(title = "产品展示" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JiayiProductRequest request) {
        return AjaxResult.toAjax(jiayiProductService.insertJiayiProduct(request));
    }

    /**
     * 修改产品展示
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:edit')")
    @Log(title = "产品展示" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JiayiProductRequest request) {
        return AjaxResult.toAjax(jiayiProductService.updateJiayiProduct(request));
    }

    /**
     * 删除产品展示
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product:remove')")
    @Log(title = "产品展示" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.toAjax(jiayiProductService.deleteJiayiProductByIds(ids));
    }
}
